package com.li.utilstest

import android.graphics.drawable.Drawable
import android.os.Parcel
import android.os.Parcelable
import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.Target
import com.github.chrisbanes.photoview.PhotoView


/**
 * @author : liyun
 * @ClassName: ImageBrowserAdapter
 * @Package com.li.utilstest
 * @Description:
 * @company: 深圳君南信息系统有限公司
 * @date 2021/7/11 16:00
 * @version v1.0
 */
class ImageBrowserAdapter() : PagerAdapter() {
    var pathList= arrayListOf<String>()
    fun setPaths(list:ArrayList<String>) {
        pathList=list
    }
    override fun getCount(): Int =pathList.size

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val photoView = PhotoView(container.context)
        Glide.with(container.context).load(pathList[position]).error(R.drawable.ic_launcher)
            .placeholder(R.drawable.ic_launcher)
            .into(photoView)
        // Now just add PhotoView to ViewPager and return it
        container.addView(
            photoView,
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        return photoView
    }

    override fun destroyItem(container: ViewGroup, position: Int, o: Any) {
        container.removeView(o as View?)
    }

    override fun isViewFromObject(view: View, o: Any): Boolean {
        return view==o
    }


}